package com.excesys.exsecs.om.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.log.annotation.SysLog;
import com.excesys.exsecs.om.entity.OmMNotice;
import com.excesys.exsecs.om.service.OmMNoticeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/ommnotice")
@Tag(name = "通知设置")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class OmMNoticeController {

	@Autowired
	private final OmMNoticeService omMNoticeService;

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param omMNotice 通知信息
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('om_m_notice_get')")
	public R getOmIRoutePointRelPage(Page page, OmMNotice omMNotice) {
		return R.ok(omMNoticeService.page(page, Wrappers.query(omMNotice)));
	}

	/**
	 * 新增
	 * @param omMNotice 新增通知信息
	 * @return
	 */
	@Operation(summary = "新增通知信息", description = "新增通知信息")
	@SysLog("新增通知信息表")
	@PostMapping("/save")
	@PreAuthorize("@pms.hasPermission('om_m_notice_post')")
	public R save(@RequestBody OmMNotice omMNotice) {
		return R.ok(omMNoticeService.save(omMNotice));
	}

	/**
	 * 通知编辑
	 *
	 */
	@Operation(summary = "新增通知信息", description = "新增通知信息")
	@SysLog("修改通知信息表")
	@PutMapping("/update")
	@PreAuthorize("@pms.hasPermission('om_m_notice_update')")
	public R updateById(@RequestBody OmMNotice omMNotice) {
		return R.ok(omMNoticeService.updateById(omMNotice));
	}

	/**
	 * 删除通知
	 */
	@Operation(summary = "删除通知信息", description = "删除通知信息")
	@SysLog("通过id删除通知信息表")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('om_m_notice_delete')")
	public R deleteById(@PathVariable Integer id) {
		return R.ok(omMNoticeService.removeById(id));
	}

}
